package com.ruoyi.web.controller.ring.app;

import cn.hutool.core.convert.Convert;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.bean.Builder;
import com.ruoyi.ring.domain.RingMyOpinionFeedback;
import com.ruoyi.ring.domain.RingMyOpinionImage;
import com.ruoyi.ring.domain.dto.RingMyOpinionFeedbackDTO;
import com.ruoyi.ring.domain.vo.MyOpinionFeedbackVO;
import com.ruoyi.ring.service.IRingMyOpinionFeedbackService;
import com.ruoyi.ring.service.IRingMyOpinionImageService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 我的意见反馈 app
 * 
 * @author liuwp
 * @date 2025-10-15
 */
@RestController
@RequestMapping("/ring/app/ring_my_opinion_feedback")
public class AppMyOpinionFeedbackController extends BaseController
{
    @Resource
    private IRingMyOpinionFeedbackService ringMyOpinionFeedbackService;

    @Resource
    private IRingMyOpinionImageService ringMyOpinionImageService;

    /**
     * 新增我的意见反馈 app
     */
    @PostMapping("/add-feedback")
    public AjaxResult addMyOpinionFeedback(RingMyOpinionFeedbackDTO dto)
    {
        return toAjax(ringMyOpinionFeedbackService.addMyOpinionFeedback(dto));
    }

    /**
     * 获取我的意见反馈详细信息 app
     */
    @GetMapping(value = "/query-feedback/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        RingMyOpinionFeedback myOpinionFeedback = ringMyOpinionFeedbackService.selectRingMyOpinionFeedbackById(id);
        MyOpinionFeedbackVO opinionFeedbackVO = Convert.convert(MyOpinionFeedbackVO.class,myOpinionFeedback);
        RingMyOpinionImage myOpinionImage = Builder.of(RingMyOpinionImage::new).with(RingMyOpinionImage::setOpinionId, id).build();
        List<RingMyOpinionImage> myOpinionImages = ringMyOpinionImageService.selectRingMyOpinionImageList(myOpinionImage);
        if(myOpinionImages.size() > 0){
            List<MyOpinionFeedbackVO.ImageVO> imageVOS = Convert.toList(MyOpinionFeedbackVO.ImageVO.class,myOpinionImages);
            opinionFeedbackVO.setImages(imageVOS);
        }
        return AjaxResult.success(opinionFeedbackVO);
    }

    /**
     * 查询我的意见反馈列表 app
     */
    @GetMapping("/query-feedback-list")
    public AjaxResult list()
    {
        RingMyOpinionFeedback ringMyOpinionFeedback = Builder.of(RingMyOpinionFeedback::new).with(RingMyOpinionFeedback::setUserId, SecurityUtils.getUserId()).build();
        List<RingMyOpinionFeedback> list = ringMyOpinionFeedbackService.selectRingMyOpinionFeedbackList(ringMyOpinionFeedback);
        return AjaxResult.success(list);
    }

}
